package com.example.gitport03;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.example.git.R;
import com.example.git.entity.Car;

import java.util.List;

public class CarAdapter extends ArrayAdapter<Car> {
    private int resourceId;

    public CarAdapter(@NonNull Context context, int resource, @NonNull List<Car> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Car car = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);

        ImageView carImg = view.findViewById(R.id.img_car);
        TextView carName = view.findViewById(R.id.text_car_name);
        TextView carBrief = view.findViewById(R.id.text_car_brief);

        carImg.setImageResource(car.getImg());
        carName.setText(car.getName());
        carBrief.setText(car.getBrief());

        return view;
    }
}
